package com.itany.corejava.code08_常用类.内部类;

import com.itany.corejava.code08_常用类.内部类.SomeOuter.SomeInner;

/**
 * @author 石小俊
 * @date 2023年05月04日 16:48
 */
public class Test03_静态内部类 {
    public static void main(String[] args) {
        SomeOuter outer = new SomeOuter();
        outer.show();

        // 非外部类实例化内部类
        // 方式一:将 外部类.内部类 当做一个类名
        // SomeOuter.SomeInner inner = new SomeOuter.SomeInner();
        // 方式二:手动导包,将外部类.内部类作为类名
        SomeInner inner = new SomeInner();
        inner.print();

    }
}

class SomeOuter {
    private String name = "admin";
    private int age = 18;
    private static String phone = "13812345678";

    public static String getPhone() {
        return phone;
    }

    public static void setPhone(String phone) {
        SomeOuter.phone = phone;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void show() {
        System.out.println("********************外部类方法开始********************");
        SomeInner inner = new SomeInner();
        System.out.println(inner.name);
        System.out.println(name);
        System.out.println("********************外部类方法结束********************");
    }

    // 定义静态内部类
    static class SomeInner {
        private String name = "alice";
        private String gender = "男";

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getGender() {
            return gender;
        }

        public void setGender(String gender) {
            this.gender = gender;
        }

        public void print() {
            System.out.println("********************内部类方法开始********************");
            SomeOuter outer = new SomeOuter();
            System.out.println(outer.name);
            System.out.println(outer.age);
            // 此时无法直接通过属性名访问外部类属性
            System.out.println(phone);
            outer.show();
            System.out.println("********************内部类方法结束********************");
        }
    }
}

